home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / FRYANEGG.ZIP / PTD_TREE.INC < prev    next >
Encoding:
Text File  |  1996-08-31  |  13.9 KB  |  404 lines

  1.  
  2. //------------------------------------------------------------------->
  3. //------------------------------------------------------------------->
  4. //
  5. // PTD_Tree.inc - Almost totally random nested loop tree!
  6. //
  7. // Created by: Paul T. Dawson
  8. //             ptdawson@voicenet.com
  9. //             http://www.voicenet.com/~ptdawson
  10. //
  11. // <=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>
  12. // <=>-<=>-<=>-<=>                 <=>-<=>-<=>-<=>
  13. // <=>-<=>-<=>-<=>  PUBLIC DOMAIN  <=>-<=>-<=>-<=>
  14. // <=>-<=>-<=>-<=>                 <=>-<=>-<=>-<=>
  15. // <=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>
  16. //
  17. // Requires POV-Ray 3.0, with the new "rand" function, and loops!
  18. //
  19. // Thank you, POV-Team, for your magnificent program!!!
  20. //
  21. //------------------------------------------------------------------->
  22. //------------------------------------------------------------------->
  23. //
  24. // Note: This file should be broken into two separate files, with the
  25. //       first file containing the "variable setting", and the second
  26. //       file with the actual "tree building". I kept both parts together
  27. //       this time, because it's a little easier that way.
  28. //
  29. // Note: This file does NOT display the tree. It just makes an object
  30. //       called "Complete_Tree". Then your scene file can show that!
  31. //
  32. // Note: Your main scene file must have all of the usual include files,
  33. //       including "colors.inc" and "textures.inc". If you use any
  34. //       special textures, like "golds" or "stones", you will need to
  35. //       include those files, too (but you-all knew all that!).
  36. //
  37. // Note: Realistic trees use a *LOT* of memory!!!
  38. //
  39. //------------------------------------------------------------------->
  40. //------------------------------------------------------------------->
  41. //
  42. // So, here's PART ONE, with the variable setting...
  43. //
  44. // You can change anything in this section (within reason!).
  45. //
  46. //------------------------------------------------------------------->
  47. //------------------------------------------------------------------->
  48. //
  49. // The seed(#) value controls the PSEUDO "random" numbers.
  50.  
  51.         #declare TREE_RAND = seed(0)
  52.  
  53. //------------------------------------------------------------------->
  54. //------------------------------------------------------------------->
  55. //
  56. // These settings control the number of branches on the tree. Each number
  57. // is NOT a total number. It's just in relation to the "parent branch".
  58. // For example, you might have 1 trunk and 5 large branches, and then put
  59. // 3 medium branches on EACH large branch. Then you could put, say, 10 small
  60. // branches on each medium one. The grand total (if you figure it all out)
  61. // would be 1 + 5 + (5*3) + (5*3*10) = 171 branches. Be careful when you
  62. // change these, because you can easily end up with thousands of branches!
  63.  
  64.         #declare Number_Of_Large_Branches = 5
  65.         #declare Number_Of_Medium_Branches = 5
  66.         #declare Number_Of_Small_Branches = 10
  67.  
  68. // The branches start out standing straight up. If you rotate the branch
  69. // by 10 degrees, it will tilt just a little. If you rotate it 90 degrees,
  70. // it will be at a right angle to the parent branch. These variables set
  71. // the allowable range of "tilt" for each branch. Remember, in this tree,
  72. // each branch gets a different RANDOM tilt. These are just the limits!
  73.  
  74.         #declare Branch_Minimum_Angle = 20
  75.         #declare Branch_Maximum_Angle = 80
  76.  
  77. // Set the size of the tree trunk, and the different branches. This is
  78. // for the length only, not the diameter. Usually, the branches get
  79. // shorter as they go outwards. You can put in any size you want, for some
  80. // very strange trees!
  81.  
  82.         #declare Tree_Trunk_Size = 10
  83.  
  84.         #declare Large_Branch_Size_Min = 2
  85.         #declare Large_Branch_Size_Max = 4
  86.  
  87.         #declare Medium_Branch_Size_Min = 2
  88.         #declare Medium_Branch_Size_Max = 4
  89.  
  90.         #declare Small_Branch_Size_Min = 2
  91.         #declare Small_Branch_Size_Max = 4
  92.  
  93. //------------------------------------------------------------------->
  94. //------------------------------------------------------------------->
  95. //
  96. // There are five different leaf styles to choose from.
  97. // These five numbers are constants - don't change them!
  98.  
  99.         #declare Leaf_Type_Realistic = 0
  100.         #declare Leaf_Type_Fast      = 1
  101.         #declare Leaf_Type_Strange   = 2
  102.         #declare Leaf_Type_Torus     = 3
  103.         #declare Leaf_Type_Mesh      = 4
  104.  
  105. // Change the Leaf_Type variable right here.
  106.  
  107.         #declare Leaf_Type = Leaf_Type_Mesh
  108.  
  109. // Set the complete texture for the leaves.
  110.  
  111.         #declare Leaf_Texture = texture { pigment { LimeGreen } }
  112.  
  113. //------------------------------------------------------------------->
  114. //------------------------------------------------------------------->
  115. //
  116. // Now, here's PART TWO, where the tree is built...
  117. //
  118. // Don't change anything below here (unless you really want to!).
  119. //
  120. //------------------------------------------------------------------->
  121. //------------------------------------------------------------------->
  122. //
  123. // Don't change these - they are calculated from the above variables.
  124.  
  125.         #declare Bmin = Branch_Minimum_Angle
  126.         #declare Bmax = Branch_Maximum_Angle - Branch_Minimum_Angle
  127.  
  128.         #declare Large_Branch_Size_Range =
  129.         Large_Branch_Size_Max - Large_Branch_Size_Min
  130.  
  131.         #declare Medium_Branch_Size_Range =
  132.         Medium_Branch_Size_Max - Medium_Branch_Size_Min
  133.  
  134.         #declare Small_Branch_Size_Range =
  135.         Small_Branch_Size_Max - Small_Branch_Size_Min
  136.  
  137. //------------------------------------------------------------------->
  138. //------------------------------------------------------------------->
  139. //
  140. // Create one of the five leaf styles.
  141. //
  142. // Note: To save memory, the leaves do not get a texture until the
  143. //       very end of the Complete_Tree union. That way, all of the leaves
  144. //       can share one texture. This saves a LOT of memory. You can
  145. //       change this around if you want to, and put the textures up
  146. //       here (memory is cheap, I know, I know!).
  147. //
  148. //------------------------------------------------------------------->
  149. //------------------------------------------------------------------->
  150. //
  151. // Now create the actual REALISTIC (sort-of) leaf.
  152.  
  153.         #if ( Leaf_Type = Leaf_Type_Realistic )
  154.  
  155.         #declare One_Leaf =
  156.  
  157.         union{
  158.  
  159.                 // Leaf part #1
  160.                 sphere{ 0, 3 scale < 0.4, 0.1, 1.0 >
  161.                         translate z * 3
  162.                         rotate x * -30
  163.                         rotate y * 0 }
  164.  
  165.                 // Leaf part #2
  166.                 sphere{ 0, 3 scale < 0.4, 0.1, 1.0 >
  167.                         translate z * 3
  168.                         rotate x * -30
  169.                         rotate y * 120 }
  170.  
  171.                 // Leaf part #3
  172.                 sphere{ 0, 3 scale < 0.4, 0.1, 1.0 >
  173.                         translate z * 3
  174.                         rotate x * -30
  175.                         rotate y * 240 }
  176.  
  177.                 // Scale the entire union. Make the leaf small for
  178.                 // testing branch placement, then make it big!
  179.  
  180.                         scale 0.2
  181.  
  182.         } // End of union.
  183.  
  184.         #end
  185.  
  186. // Now create the actual FAST leaf.
  187.  
  188.         #if ( Leaf_Type = Leaf_Type_Fast )
  189.  
  190.                 #declare One_Leaf = sphere{ 0, 0.5 }
  191.  
  192.         #end
  193.  
  194. // Now create the actual STRANGE leaf. Change this to anything!
  195.  
  196.         #if ( Leaf_Type = Leaf_Type_Strange )
  197.  
  198.         #declare One_Leaf = union {
  199.  
  200.                 sphere { 0, 0.3 }
  201.  
  202.                 difference {
  203.  
  204.                         box { < -1, -1, -1 > < 1, 1, 1 > }
  205.  
  206.                         sphere { 0, 1.3 }
  207.  
  208.                 } // End of difference.
  209.  
  210.         } // End of union.
  211.  
  212.         #end
  213.  
  214. // Now create the actual TORUS leaf. This one has a texture!!!
  215.  
  216.         #if ( Leaf_Type = Leaf_Type_Torus )
  217.  
  218.         #declare One_Leaf = union {
  219.  
  220.                 torus { 1, 0.25 pigment { checker Red, Yellow scale 10 } }
  221.  
  222.                 cylinder { < -1, 0,  0 > < 1, 0, 0 >, 0.1
  223.                 pigment { checker Blue, Cyan scale 0.1 } }
  224.  
  225.                 cylinder { <  0, 0, -1 > < 0, 0, 1 >, 0.1
  226.                 pigment { checker Blue, Cyan scale 0.1 } }
  227.  
  228.         } // End of union.
  229.  
  230.         #end
  231.  
  232. // Create the MESH leaf object - with 200 little triangles!!!
  233.         
  234.         #if ( Leaf_Type = Leaf_Type_Mesh )
  235.  
  236.         #declare One_Leaf = mesh {
  237.  
  238.         #declare A = 1 #while ( A <= 200 )
  239.         
  240.                 // Calculate random location for first point.
  241.                 #declare X1 = ( rand(R) * 2 ) - 1
  242.                 #declare Y1 = ( rand(R) * 2 ) - 1
  243.                 #declare Z1 = ( rand(R) * 2 ) - 1
  244.  
  245.                 // Move a little way from *first* point.
  246.                 #declare X2 = X1 + ( rand(R) * 0.5 ) - 0.25
  247.                 #declare Y2 = Y1 + ( rand(R) * 0.5 ) - 0.25
  248.                 #declare Z2 = Z1 + ( rand(R) * 0.5 ) - 0.25
  249.  
  250.                 // Move a little way from *first* point.
  251.                 #declare X3 = X1 + ( rand(R) * 0.5 ) - 0.25
  252.                 #declare Y3 = Y1 + ( rand(R) * 0.5 ) - 0.25
  253.                 #declare Z3 = Z1 + ( rand(R) * 0.5 ) - 0.25
  254.                 
  255.                 // Make the triangle.
  256.                 triangle { <X1, Y1, Z1>, <X2, Y2, Z2>, <X3, Y3, Z3> }
  257.  
  258.         #declare A = A + 1 #end
  259.  
  260.         } // End of mesh.
  261.  
  262.         #end
  263.  
  264. //------------------------------------------------------------------->
  265. //------------------------------------------------------------------->
  266. //
  267. // Now create the tree trunk.
  268.  
  269.         #declare Tree_Trunk = cone {
  270.                 < 0, 0, 0 >, 1.00 < 0, Tree_Trunk_Size, 0 >, 0.80
  271.                 pigment { Brown_Agate scale 0.1 } }
  272.  
  273. //------------------------------------------------------------------->
  274. //------------------------------------------------------------------->
  275. //
  276. // Now we begin the CONFUSING nested loops. They create a big union
  277. // called "Complete_Tree". We start with one trunk, and add some large
  278. // branches to it. Then, for each large branch, we add a few medium
  279. // branches - each one is at a random angle. Then, in the inner loop,
  280. // we add small branches. Each one of the small branches gets one leaf
  281. // object attached to it. Whew!
  282. //
  283. // The loops MUST be nested like this - it's the only way to give each
  284. // and every branch a random tilt (relative to the parent branch).
  285. //
  286. // The loops are NOT indented properly, because that put the inner loop
  287. // way off the screen, making things even more confusing!
  288.  
  289.         #declare Complete_Tree =
  290.  
  291.         union {
  292.  
  293.         object { Tree_Trunk }
  294.  
  295.         #declare A = 0 #while ( A < 360 )
  296.  
  297.         union {
  298.  
  299. // Make one large branch.
  300.  
  301.         #declare This_Large_Branch_Size =
  302.                 ( rand(TREE_RAND) * Large_Branch_Size_Range ) +
  303.                 Large_Branch_Size_Min
  304.  
  305.         cone {<0,0,0>,0.60 <0,This_Large_Branch_Size,0>,0.40
  306.                 pigment{Brown_Agate scale 0.1 } }
  307.  
  308. // Loop to put medium branches on that large branch.
  309.  
  310.         #declare B = 0 #while ( B < 360 )
  311.  
  312.         union {
  313.  
  314.         #declare This_Medium_Branch_Size =
  315.                 ( rand(TREE_RAND) * Medium_Branch_Size_Range ) +
  316.                 Medium_Branch_Size_Min
  317.  
  318.         cone { <0,0,0>,0.30 <0,This_Medium_Branch_Size,0>,0.20
  319.                 pigment{Brown_Agate scale 0.1 } }
  320.  
  321. // Loop to put small branches on that medium branch.
  322.  
  323.         #declare C = 0 #while ( C < 360 )
  324.  
  325.         #declare This_Small_Branch_Size =
  326.                 ( rand(TREE_RAND) * Small_Branch_Size_Range ) +
  327.                 Small_Branch_Size_Min
  328.  
  329.         union {
  330.  
  331.         cone { <0,0,0>,0.10 <0,This_Small_Branch_Size,0>,0.05
  332.                 pigment { Brown_Agate scale 0.1 }
  333.                 } // End of cone.
  334.  
  335. // The leaf at the end of the small branch.
  336.  
  337.         object { One_Leaf translate y * This_Small_Branch_Size }
  338.  
  339.         // First, spin the vertical branch to a random angle.
  340.         // The branch doesn't really change - this actually
  341.         // just spins the leaf around!
  342.  
  343.                 #declare SpinAngle = (rand(TREE_RAND)*360)
  344.                 rotate y * SpinAngle
  345.  
  346.         // Now, tilt it over a little.
  347.                 #declare BranchAngle = (rand(TREE_RAND)*Bmax)+Bmin
  348.                 rotate z * BranchAngle
  349.  
  350.         // Rotate it into place, with a little random wiggle.
  351.                 #declare Wiggle=(rand(TREE_RAND)*20)-10
  352.                 rotate y * (C + Wiggle)
  353.  
  354.         // Move it up to the top of the Medium_Branch.
  355.                 translate y * This_Medium_Branch_Size
  356.  
  357.         } // End of object.
  358.  
  359.         #declare C = C + ( 360 / Number_Of_Small_Branches ) #end
  360.  
  361.         #declare BranchAngle = (rand(TREE_RAND)*Bmax)+Bmin
  362.         rotate z * BranchAngle
  363.  
  364.         #declare Wiggle=(rand(TREE_RAND)*20)-10
  365.         rotate y * ( B + Wiggle )
  366.  
  367.         // Move the Medium_Branch up to the top of the Large_Branch.
  368.                 translate y * This_Large_Branch_Size
  369.  
  370.         } // End of union.
  371.  
  372.         #declare B = B + ( 360 / Number_Of_Medium_Branches ) #end
  373.  
  374.         #declare BranchAngle = (rand(TREE_RAND)*Bmax)+Bmin
  375.         rotate z * BranchAngle
  376.  
  377.         #declare Wiggle=(rand(TREE_RAND)*20)-10
  378.         rotate y * ( A + Wiggle )
  379.  
  380.         // Move the Large_Branch up to the top of the Tree_Trunk.
  381.                 translate y * Tree_Trunk_Size
  382.  
  383.         } // End of union.
  384.  
  385.         #declare A = A + ( 360 / Number_Of_Large_Branches ) #end
  386.  
  387.         // Now, turn all of the leaves green! This doesn't change the
  388.         // branches, because they already have a pigment.
  389.  
  390.                 texture { Leaf_Texture }
  391.  
  392.     } // end of Complete_Tree union
  393.  
  394. //------------------------------------------------------------------->
  395. //------------------------------------------------------------------->
  396. //
  397. // Now return to your main file and show "Complete_Tree".
  398. //
  399. //------------------------------------------------------------------->
  400. //------------------------------------------------------------------->
  401. //
  402. // End of this file - bye!
  403.  
  404.